<template>
  <div class="default-box box">
    <div class="box-title">
      <div class="vertical-line" />
      <span class="black">院校对比</span>
    </div>
    <div class="content">
      <!-- <input type="text" placeholder="搜索院校名称"> -->
      <SearchInput placeholder="搜索院校名称" @selectOption="select" />
      <div v-for="item in selectList" :key="item.name" class="item flex">
        <div class="name">{{ item.name }}</div>
        <div class="del" @click="del(item)">×</div>
      </div>
      <button @click="compare">开始对比（已选择{{ selectList.length }}/4）</button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import SearchInput from '@/components/searchInput/index.vue'
import { useRouter } from 'vue-router';
const selectList = ref<any>([{ id: '1', name: '北京大学' }])
const router = useRouter()

const del = (item: any) => {
  selectList.value = selectList.value.filter((i: any) => i.id !== item.id)
}
const select = (item: any) => {
  if (selectList.value.length >= 4 || selectList.value.filter((i: any) => i.id === item.id).length) {
    return
  }
  selectList.value.push(item)
}
const compare = () => {
  router.push({
    path: '/universityCompare',
    query: {
      id: selectList.value.map((i: any) => i.id).join(','),
    },
  })
}
</script>

<style lang="less" scoped>
@import "./index.less";
</style>
